package com.monitor.app_monitor.service.quartz.utils;


import org.apache.commons.codec.binary.Base64;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.net.URLEncoder;

public class CreateSign{

    public static String[] getSign() throws Exception {

        final String[] strings = new String[2];
        Long timestamp = System.currentTimeMillis();
        String secret = "SECcb889f6319b6a6e12c2880af8c1817abb9363fc76e59776937d2a9b56dd894d8";

        String stringToSign = timestamp + "\n" + secret;
        Mac mac = Mac.getInstance("HmacSHA256");
        mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
        byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
        String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)),"UTF-8");
        strings[0] = String.valueOf(timestamp);
        strings[1] = sign;
        return  strings;
    }

}